#include <stdio.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include<linux/in.h>
#include<stdlib.h>
#include<string.h>
#define N 128

int main(int argc, const char *argv[])
{
	int sockfd;
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd<0)
	{
		perror("socket error");
		exit(-1);
	}
	printf("socket success\n");

	struct sockaddr_in serveraddr;                
	serveraddr.sin_family=AF_INET;
	serveraddr.sin_port=htons(atoi(argv[2]));
	serveraddr.sin_addr.s_addr=inet_addr(argv[1]);

	socklen_t addrlen=sizeof(serveraddr);

	if(connect(sockfd,(struct sockaddr *)&serveraddr,addrlen)<0)
	{
		perror("connect error");
		exit(-1);
	}
	printf("connect success\n");

	char buf[N]={0};
	while(1)
	{
		fgets(buf,sizeof(buf),stdin);
		buf[strlen(buf)-1]='\0';
		send(sockfd,buf,sizeof(buf),0);
		recv(sockfd,buf,sizeof(buf),0);
		printf("buf:%s\n",buf);
	}

	return 0;
}
